package org.dei.perla.aggregates;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.dei.perla.parser.expressions.ConstantFloat;

public class SampleMin implements AggregationOperator {

	@Override
	public ConstantFloat doOperation(ConstantFloat[] sample) {
		double min = sample[0].getValueFloat();
		int len = sample.length;
		for (int i = 1; i < len; i++) {
			double tValue = sample[i].getValueFloat();
			if ( tValue < min){
				min = tValue;
			} 
		}
		 return new ConstantFloat(min); 
	}

	@Override
	public ConstantFloat doOperation(List<ConstantFloat> sample) {
		
		Iterator<ConstantFloat> it = sample.iterator();
		double min = it.next().getValueFloat();
		while (it.hasNext()) {
			Double tConstantFloat = it.next().getValueFloat();
			if (tConstantFloat < min ){
				min = tConstantFloat;
			}
		}
       return new ConstantFloat(min);
	}

}
